package com.zhy.learning.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhy
 * @version 1.0.0
 * @ClassName RedisController.java
 * @Description TODO
 * @createTime 2021年07月27日 15:42:00
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/string/set/{key}/{value}")
    public Object setString(@PathVariable String key, @PathVariable String value) {
        redisTemplate.opsForValue().set(key, value);
        return "success";
    }

    @GetMapping("/string/get/{key}")
    public Object getString(@PathVariable String key) {
        return redisTemplate.opsForValue().get(key);
    }
}
